/**
 * 
 */
package cx3k.GUI;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;

import javax.swing.*;

import cx3k.scheduler.Scheduler;
import cx3k.scheduler.objects.Course;

/**
 * @author Chris
 *
 */
public class SearchResultsPane extends JPanel {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	GridBagLayout gbl;
	GridBagConstraints gbc;
	int nextRow;
	ClassInfo classInfo;
	CompletedClasses completedClasses;
	SchedulePane scheduler;

	public SearchResultsPane(ClassInfo ci, CompletedClasses cc, SchedulePane s) {
		this.scheduler = s;
		
		this.setBackground(MainWindow.MAINCOLOR);
		this.classInfo = ci;
		this.completedClasses = cc;
		
		gbl = new GridBagLayout();
		this.setLayout(gbl);
		gbc = new GridBagConstraints();
		nextRow = 0;
		
		gbc.gridx = 0;
		gbc.gridy = 0; 
		gbc.gridwidth = 1; 
		gbc.gridheight = 1; 
		gbc.weightx = 100; 
		gbc.weighty = 10; 
		gbc.fill = GridBagConstraints.HORIZONTAL; 
		gbc.anchor = GridBagConstraints.FIRST_LINE_START; 	
	}
	
	public void addCourse(Course c) {
		this.removeAll();
		this.nextRow = 0;
		this.gbc.gridy = nextRow++;
		SearchClassDisplay sd = new SearchClassDisplay(new ScheduledCourseGroup(c), this.classInfo, this.completedClasses, scheduler);
		this.gbl.setConstraints(sd, this.gbc);
		this.add(sd);
		this.updateUI();
	}
	
	public void showResults(ArrayList<Course> courses) {		
		for (Course c: courses) {
			SearchClassDisplay sd = new SearchClassDisplay(new ScheduledCourseGroup(c), this.classInfo, this.completedClasses, scheduler);
			this.gbc.gridy = this.nextRow++;
			this.gbl.setConstraints(sd, this.gbc);
			this.add(sd);
		}
		
		this.updateUI();
	}
	
	public void clear() {
		this.removeAll();
		this.nextRow = 0;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
